import { ref, computed } from 'vue'
import { defineStore, mapActions } from 'pinia'

export const useUserStore = defineStore('loginUser', {
   state: () => {
    return{
      cur_user: sessionStorage.getItem('curUser')!=null?JSON.parse(sessionStorage.getItem('curUser')):null
    }
   },
   getters:{
     isLogin(){
       return this.cur_user!=null;
     },
   },
   actions:{
     login(user){
        sessionStorage.setItem('curUser', JSON.stringify(user));
        this.cur_user=user;
     },
     logout(){
        sessionStorage.removeItem('curUser');
        this.cur_user=null;
     },
     saveUser(user){
       this.cur_user = user
     },
     clearUser(){
       this.cur_user = null
     }
   }
})
